package sveta.pages;

    import org.openqa.selenium.By;
	import org.openqa.selenium.WebElement;
	import org.openqa.selenium.support.FindBy;

	import static org.openqa.selenium.support.ui.ExpectedConditions.*;

	public class AddFilmPage extends AnyPage {

		public AddFilmPage(PageManager pages) {
			super(pages);
		}

	  @FindBy(css = "img[alt=\"Add movie\"]")
	  private WebElement addButton;

	  @FindBy(name = "imdbid")
	  private WebElement numberField;

	  @FindBy(name = "name")
	  private WebElement titleField;
	  
	  @FindBy(name = "year")
	  private WebElement yearField;
	  
	  @FindBy(id = "submit")
	  private WebElement submitButton;
	  
	  @FindBy(linkText = "Home")
	  private WebElement homeButton;
	  
	  @FindBy(className = "maininfo_full")
	  private WebElement classField;
	  
	  @FindBy(className = "content")
	  private WebElement noFilmField;
	  
	  @FindBy(css = "h2")
	  private WebElement classFieldCss;
	  
	  @FindBy(css = "img[alt=\"Remove\"]")
	  private WebElement removeButton;
	  
	  @FindBy(id = "imdbsearch")
	  private WebElement searchField;

	  @FindBy(css = "input[type=\"submit\"]")
	  private WebElement searchButton;
	  
	  @FindBy(css = ".imdbmovies")
	  private WebElement moviesField;
	  
	  public AddFilmPage setNumberField(String text) {
	    numberField.sendKeys(text);
	    return this;
	  }

	  public AddFilmPage setYearField(String text) {
		yearField.sendKeys(text);
	    return this;
	  }
	  
	  public AddFilmPage setNameField(String text) {
		 titleField.sendKeys(text);
		 return this;
	  }
	  
	  public AddFilmPage setSearchField(String text) {
		     searchField.clear();
		     searchField.sendKeys(text);
			 return this;
		  }
	  
	  public void clickSearchButton() {
		    searchButton.click();
		  }
	  
	  public void clickAddButton() {
	    addButton.click();
	  }
	  
	  public void clickSubmitButton() {
		    submitButton.click();
		  }
	  
	  public void clickRemoveButton() {
		    removeButton.click();
		  }
	  
	  public void clickHomeButton() {
		    homeButton.click();
		  }
      public String getFilmInfo(){
    	  return classField.findElement(By.cssSelector("h2")).getText();
      }
      
      public String getTextNoFilm(){
    	  return noFilmField.getText();
      }
      
      public int getFilmCount(){
    	  return moviesField.findElements(By.tagName("tr")).size();
      }
/*	  public LoginPage ensurePageLoaded() {
	    super.ensurePageLoaded();
	    wait.until(presenceOfElementLocated(By.id("loginform")));
	    return this;
	  }
	}*/


}
